home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / alrtdlgs.sit / alertdialogs.sit / Alerts Dialogs v. 2.0 / card_4010.txt < prev    next >
Text File  |  1988-11-07  |  6KB  |  253 lines

  1. -- card: 4010 from stack: in.0
  2. -- bmap block id: 6392
  3. -- flags: 0000
  4. -- background id: 2745
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 01
  10. -- high flags: 0007
  11. -- rect: left=0 top=126 right=312 bottom=364
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 3
  16. -- text size: 9
  17. -- style flags: 0
  18. -- line height: 12
  19. -- part name: source code listing
  20.  
  21.  
  22. -- part 3 (button)
  23. -- low flags: 00
  24. -- high flags: A002
  25. -- rect: left=0 top=311 right=330 bottom=124
  26. -- title width / last selected line: 0
  27. -- icon id / first selected line: 0 / 0
  28. -- text alignment: 1
  29. -- font id: 0
  30. -- text size: 12
  31. -- style flags: 0
  32. -- line height: 16
  33. -- part name: Copy Source Code
  34.  
  35.  
  36. -- part contents for background part 3
  37. ----- text -----
  38. For those of you interested here is the source code listing for Alerts Dialogs in HyperCard done in LightSpeed PascalΓäó. It was compiled and linked with the DAPasLib and MacTraps. Then it was built and saved as a resource of type XCMD and pasted along with the related resources via ResEdit into this stack.
  39.  
  40. -- part contents for card part 1
  41. ----- text -----
  42. {┬⌐1988 by Maurice Volaski and portions ┬⌐1986,1987 by Think Technologies, Inc.}
  43.  
  44. unit AlertsForHypercard;
  45. interface
  46.  type
  47.   XCmdPtr = ^XCmdBlock;
  48.   XCmdBlock = record
  49.     paramCount : INTEGER;
  50.     params : array[1..16] of Handle;
  51.     returnValue : Handle;
  52.     passFlag : BOOLEAN;
  53.  
  54.     entryPoint : ProcPtr;
  55.     request : INTEGER;
  56.     result : INTEGER;
  57.     inArgs : array[1..8] of LongInt;
  58.     outArgs : array[1..4] of LongInt;
  59.    end;
  60.  
  61.  procedure main (paramPtr : XCmdPtr);
  62.  
  63. implementation
  64.  procedure Alert (paramPtr : XCmdPtr);
  65.  forward;
  66.  
  67.  procedure main;
  68.  begin
  69.   Alert(paramPtr);
  70.  end;
  71.  
  72.  procedure sound (soundnumber : integer);
  73.  begin
  74.   soundNumber := 1;
  75.   Sysbeep(10);
  76.  end;
  77.  
  78.  procedure nothing (soundNumber : integer);
  79.  begin
  80.   soundNumber := 0;
  81.  end;
  82.  
  83.  procedure Alert;
  84.   const
  85.    xreqPasToZero = 7;
  86.    xreqZeroToPas = 8;
  87.    xreqStrToNum = 10;
  88.    xreqStrToBool = 11;
  89.    xreqNumToStr = 14;
  90.    OKAlert = 2594;
  91.    CancelAlert = 4381;
  92.    OKCancelAlert = 15163;
  93.    CancelOKAlert = 16661;
  94.   type
  95.    Str31 = string[31];
  96.   var
  97.    alertBox, icon, btnArgmt, NumOfBtns, beep : integer;
  98.    theText, theString : Str255;
  99.  
  100.   procedure DoJsr (addr : ProcPtr);
  101.   inline
  102.    $205F, $4E90;
  103.  
  104.   procedure ZeroToPas (zeroStr : Ptr;
  105.      var pasStr : Str255);
  106.   begin
  107.    with paramPtr^ do
  108.     begin
  109.      inArgs[1] := ORD(zeroStr);
  110.      inArgs[2] := ORD(@pasStr);
  111.      request := xreqZeroToPas;
  112.      DoJsr(entryPoint);
  113.     end;
  114.   end;
  115.  
  116.   function PasToZero (str : Str255) : Handle;
  117.   begin
  118.    with paramPtr^ do
  119.     begin
  120.      inArgs[1] := ORD(@str);
  121.      request := xreqPasToZero;
  122.      DoJsr(entryPoint);
  123.      PasToZero := Handle(outArgs[1]);
  124.     end;
  125.   end;
  126.  
  127.   function StrToNum (str : Str31) : LongInt;
  128.   begin
  129.    with paramPtr^ do
  130.     begin
  131.      inArgs[1] := ORD(@str);
  132.      request := xreqStrToNum;
  133.      DoJsr(entryPoint);
  134.      StrToNum := outArgs[1];
  135.     end;
  136.   end;
  137.  
  138.   function NumToStr (num : LongInt) : Str31;
  139.    var
  140.     str : Str31;
  141.   begin
  142.    with paramPtr^ do
  143.     begin
  144.      inArgs[1] := num;
  145.      inArgs[2] := ORD(@str);
  146.      request := xreqNumToStr;
  147.      DoJsr(entryPoint);
  148.      NumToStr := str;
  149.     end;
  150.   end;
  151.  
  152.   function StrToBool (str : Str31) : BOOLEAN;
  153.   begin
  154.    with paramPtr^ do
  155.     begin
  156.      inArgs[1] := ORD(@str);
  157.      request := xreqStrToBool;
  158.      DoJsr(entryPoint);
  159.      StrToBool := BOOLEAN(outArgs[1]);
  160.     end;
  161.   end;
  162.  
  163.   procedure OneButton;
  164.    procedure DoOneBtnAlert (whichdialog : integer);
  165.    begin {begin DoOneBtnAlert}
  166.     case icon of
  167.      1 : 
  168.      alertBox := NoteAlert(whichdialog, nil);
  169.      2 : 
  170.      alertBox := CautionAlert(whichdialog, nil);
  171.      3 : 
  172.      alertBox := StopAlert(whichdialog, nil);
  173.     end; {end case}
  174.    end; {end DoOneBtnAlert}
  175.   begin {begin OneButton}
  176.    if btnArgmt = 1 then
  177.     DoOneBtnAlert(OKAlert)
  178.    else
  179.     DoOneBtnAlert(CancelAlert)
  180.   end; {end OneButton}
  181.   procedure TwoButton;
  182.    procedure DoTwoBtnAlert (whichDialog : integer);
  183.     procedure PassResult (theAlertItem : integer);
  184.      var
  185.      resultString : str31;
  186.     begin {begin PassResult}
  187.      if btnArgmt = 3 then
  188.      if theAlertItem = 1 then
  189.      begin
  190.      resultString := NumToStr(1);
  191.      paramPtr^.returnValue := PasToZero(resultString);
  192.      end
  193.      else
  194.      begin
  195.      resultString := NumToStr(2);
  196.      paramPtr^.returnValue := PasToZero(resultString);
  197.      end
  198.      else if theAlertItem = 1 then
  199.      begin
  200.      resultString := NumToStr(2);
  201.      paramPtr^.returnValue := PasToZero(resultString);
  202.      end
  203.      else
  204.      begin
  205.      resultString := NumToStr(1);
  206.      paramPtr^.returnValue := PasToZero(resultString);
  207.      end;
  208.     end; {end PassResult}
  209.    begin {begin DoTwoBtnAlert}
  210.     case icon of
  211.      1 : 
  212.      alertBox := NoteAlert(whichDialog, nil);
  213.      2 : 
  214.      alertBox := CautionAlert(whichDialog, nil);
  215.      3 : 
  216.      alertBox := StopAlert(whichDialog, nil);
  217.     end; {end case}
  218.     PassResult(alertBox);
  219.    end; {end DoTwoBtnAlert}
  220.   begin {begin TwoButton}
  221.    if btnArgmt = 3 then
  222.     DoTwoBtnAlert(OKCancelAlert)
  223.    else
  224.     DoTwoBtnAlert(CancelOKAlert);
  225.   end; {end TwoButton}
  226.  
  227.  begin {begin Alert}
  228.   with paramPtr^ do
  229.    begin
  230.     ZeroToPas(params[1]^, theString);
  231.     icon := StrToNum(theString);
  232.     ZeroToPas(params[2]^, theString);
  233.     btnArgmt := StrToNum(theString);
  234.     ZeroToPas(params[3]^, theString);
  235.     theText := theString;
  236.     ZeroToPas(params[4]^, theString);
  237.     beep := StrToNum(theString);
  238.    end; {end while}
  239.   ParamText(theText, '', '', '');
  240.   if beep = 1 then
  241.    ErrorSound(@sound)
  242.   else if beep = 0 then
  243.    ErrorSound(@nothing);
  244.   case btnArgmt of
  245.    1, 2 : 
  246.     oneButton;
  247.    3, 4 : 
  248.     twoButton;
  249.   end; {end case}
  250.  end; {end Alert}
  251. end. {end unit}
  252.  
  253.